package com.gztms.travelmgnt.controller;

import com.gztms.travelmgnt.pojo.AttrCate;
import com.gztms.travelmgnt.pojo.Attractions;
import com.gztms.travelmgnt.service.AttractionsService;
import com.gztms.utils.ResultUtil;
import com.gztms.utils.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @author Zoey
 * @date 2023/4/19 20:57
 * @Description TODO
 **/
@RestController
@RequestMapping("/travel")
public class AttractionsController {
    @Autowired
    private AttractionsService attractionsService;

    /**
     * 添加景区
     * @param
     * @param attractions
     * @return
     * @throws IOException
     */
    @PostMapping("/addAttr")
    public ResultUtil addAttr(
                              @RequestBody Attractions attractions ) throws IOException {
//        String bannerUrl = UploadUtil.uploadImage(file);
//        Attractions attractions = new Attractions();
//        attractions.setName(name);
//        attractions.setAreaId(areaId);
//        attractions.setAttrDesc(attrDesc);
//        attractions.setAddress(address);
//        attractions.setOpenTime(openTime);
//        attractions.setTicketNotice(ticketNotice);
//        attractions.setAttrCateId(attrCateId);
//        attractions.setPrice(price);
//        attractions.setLimitPerson(limitPerson);
//        attractions.setBannerUrl(bannerUrl);
        System.out.println("attractions: " + attractions);

        return attractionsService.addAttr(attractions);
    }

    /**
     * 删除景区
     * @param attrId
     * @return
     */
    @PostMapping("/delAttrById/{id}")
    public ResultUtil delAttrById(@PathVariable(value = "id") Integer attrId) {
        return attractionsService.delAttrById(attrId);
    }

    /**
     *
     * @param attractions
     * @return
     */
    @PostMapping("/updateAttr")
    public ResultUtil updateAttr(@RequestBody Attractions attractions) {
        return attractionsService.updateAttr(attractions);
    }
//    public ResultUtil updateAttr(
//            @RequestParam(value = "attrId") Integer attrId,
//            @RequestParam(value = "name") String name,
//            @RequestParam(value = "areaId") Integer areaId,
//            @RequestParam(value = "attrDesc") String attrDesc,
//            @RequestParam(value = "address") String address,
//            @RequestParam(value = "openTime") String openTime,
//            @RequestParam(value = "ticketNotice") String ticketNotice,
//            @RequestParam(value = "AttrCateId") Integer attrCateId,
//            @RequestParam(value = "price") Double price,
//            @RequestParam(value = "limitPerson") Integer limitPerson) throws IOException {
//
//        Attractions attractions = new Attractions();
//        attractions.setAttrId(attrId);
//        attractions.setName(name);
//        attractions.setAreaId(areaId);
//        attractions.setAttrDesc(attrDesc);
//        attractions.setAddress(address);
//        attractions.setOpenTime(openTime);
//        attractions.setTicketNotice(ticketNotice);
//        attractions.setAttrCateId(attrCateId);
//        // 转换金钱格式
//        BigDecimal bigDecimal = new BigDecimal(price);
//        attractions.setPrice(bigDecimal);
//        attractions.setLimitPerson(limitPerson);
//
//        System.out.println("attractions: " + attractions);
//
//        return attractionsService.updateAttr(attractions);
//    }

    /**
     * 上传景区图片
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/updateAttrBanner")
    public ResultUtil updateAttrBanner(@RequestParam(value = "file") MultipartFile file ) throws IOException {
        String bannerUrl = UploadUtil.uploadImage(file);
        return attractionsService.updateAttrBanner(bannerUrl);
    }

    /**
     * 查询全部旅游景点
     * @return
     */
    @GetMapping("/findAttrs")
    public ResultUtil findAttrs(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize){
        return attractionsService.findAttrs(pageNum, pageSize);
    }

    /**
     * 查询景区详细信息
     * @param attrId
     * @return
     */
    @GetMapping("/findAttrById/{attrId}")
    public ResultUtil findAttrById(@PathVariable Integer attrId){
        return attractionsService.findAttrById(attrId);
    }


    /**
     * 查询所有地区
     * @return
     */
    @GetMapping("/findAllArea")
    public ResultUtil findAllArea() {
        return attractionsService.findAllArea();
    }

    /**
     * 查询所有景区类别
     * @return
     */
    @GetMapping("/findAllCate")
    public ResultUtil findAllCate() {
        return attractionsService.findAllCate();
    }

    /**
     * 添加景区类别
     * @param cateName
     * @return
     */
    @PostMapping("/addCate")
    public ResultUtil addCate(@RequestParam(value = "cateName") String cateName) {
        AttrCate attrCate = new AttrCate();
        attrCate.setCateName(cateName);
        return attractionsService.addAttrCate(attrCate);
    }

    /**
     * 修改景区类别
     * @param attrCate
     * @return
     */
    @PostMapping("/updateCate")
    public ResultUtil updateCate(@RequestParam(value = "attrCate") AttrCate attrCate) {
        return attractionsService.updateAttrCate(attrCate);
    }

    @GetMapping("/searchAttrList")
    public ResultUtil searchAttrList(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "attrCateId", required = false) Integer attrCateId,
            @RequestParam(value = "areaId", required = false) Integer areaId) {

        return  attractionsService.searchAttrList(pageNum,pageSize,name,attrCateId,areaId);
    }

    @GetMapping("/recommendAttr")
    public ResultUtil recommendAttr(){
        return attractionsService.recommendAttr();
    }



}
